package com.akkainaction.cluster.createcluster;

import akka.actor.ActorSystem;
import akka.actor.Address;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.cluster.Cluster;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;

public class MyNode extends UntypedActor {

    @Override
    public void onReceive(Object msg) throws Exception {
        System.out.println(getSelf() + "收到消息:[" + msg + "]");
    }

    public static void main(String[] args) {
        Config config = ConfigFactory.parseString("akka.remote.netty.tcp.port=2555")
                .withFallback(ConfigFactory.load("akka-cluster-my-node.conf"));
        ActorSystem system = ActorSystem.create("sys", config);
        system.actorOf(Props.create(MyNode.class), "myNode");
        Cluster cluster = Cluster.get(system);
        Address address = new Address("akka.tcp", "sys", "127.0.0.1", 2550);
        cluster.join(address);
    }
}
